﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jumpton.SFA.Server.BusinessRule.InStoreDataMeasures;
using Jumpton.SFA.Server.Entity;
using Jumpton.Persistent;
using Jumpton.SFA.Server.BusinessRule.MasterData;

/// <summary>
/// 常规指标维护
/// Update By:Allen Jiang
/// Update Time:2008-12-26
/// Description:
///     修改常规指标维护在一个页面。
/// </summary>
public partial class InStoreDataMeasures_MeasuresDetail_SelectCustomer : PageBase
{

    private const string REQUST_MGID = "MGID";
    private int MGID = 0;
    public string jsoncustomers = "";
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Request.QueryString[REQUST_MGID] != null)
        {
            int.TryParse(Request.QueryString[REQUST_MGID], out MGID);
        }
        else
        {
            //ShowMessage("非法访问或参数错误", "MeasuresGroup_List.aspx");
            //return;
        }
        if (!IsPostBack)
        {
            GetMeasuresDetailBind();
            ViewState["url"] = Request.UrlReferrer == null ? "MeasuresGroup_List.aspx" : Request.UrlReferrer.ToString();
        }
    }

    /// <summary>
    /// 数据绑定
    /// </summary>
    public void GetMeasuresDetailBind()
    {
        string where = "";
        if (ddl_active.SelectedValue != "")
        {
            where = " AND ACTIVE=" + ddl_active.SelectedValue;
        }
        if (txt_key.Text != "")
        {
            where += " AND NAME LIKE '%"+txt_key.Text+"%'";
        }
        DataTable dt = CustomerManager.GetCustomersByDomainID(MyStateManager.DomainID,MGID,where).Tables[0];
        if (dt.Rows.Count > 0)
        {
            jsoncustomers = JSONHelper.DataTableToJSON(dt);
            jsoncustomers = jsoncustomers.Insert(1, "{ id:1, pId:0, name:\"全部\", open:true,checked:false, icon:\"../css/zTreeStyle/img/personal.png\"},");
        }
        else
        {
            jsoncustomers = "[{ id:1, pId:0, name:\"全部\", open:true, icon:\"../css/zTreeStyle/img/personal.png\"}]";
        }
        //ObjectTable ot = CustomerManager.GetCustomers(" where DOMAINID="+MyStateManager.DomainID+" AND MEASUREPROFILEID="+MGID);
        //ListBox

    }


    protected void btnSearch_Click(object sender, EventArgs e)
    {
        GetMeasuresDetailBind();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {

        string customerIDS = "";
        string msg = "";
        if (MGID > 0)
        {
            try
            {
                customerIDS = hidcustomers.Value.TrimStart(',');
                //MeasuresManager.AssignCustomersMeasure(customerIDS, MGID, MyStateManager.DomainID);
            }
            catch (Exception ex) { msg = ex.Message; }
        }
        else
        {
            ShowMessage("保存失败", Request.Url.ToString());
            return;
        }

        if (msg != "")
        {
            ShowMessage("保存失败，" + msg);
        }
        else
        {
            ShowMessage("保存成功", ViewState["url"].ToString());
        }
    }
}
